{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "25ced253-004d-4d9a-8a20-b6864c02ba7f",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true,
    "tags": []
   },
   "source": [
    "# Using a GNN model for user cell prediction and making predictions using Inductive inference\n",
    "\n",
    "This notebook goes over how to use the Neptune ML sagemaker endpoint to make predictions with Gremlin Queries on new nodes\n",
    "\n",
    "This notebook relies on having run notebook 3a-TransductiveMode-CellPrediction to get a Neptune ML SageMaker model endpoint.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebec4304-46f7-43a7-9c66-069e97f437d5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# fill the inductive endpoint with the same endpoint from the previous notebook\n",
    "endpoint_inductive = '<replace with endpoint>'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29e437b2-1b78-49c9-90f6-4007a8b6909f",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Inductive prediction with Gremlin queries\n",
    "### load new user and some user edges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9e78ec8-4494-4772-a415-166f8ba3a28f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%load -s s3://neptuneml-data/telco-graph/inductive-data -f csv -p OVERSUBSCRIBE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56e06297-ed7e-406d-a63d-f19d3a1b04e9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V()\n",
    ".hasId(\"user_20000\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9b394cd-45bb-4876-91ec-2e6ccb9ed5a6",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V()\n",
    ".hasId(\"user_20000\")\n",
    ".outE()\n",
    ".hasLabel(\"user_live_cell\")\n",
    ".inV()\n",
    ".valueMap(true, \"name\")\n",
    ".groupCount()\n",
    ".unfold()\n",
    ".order()\n",
    ".by(values, desc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03dd809a-8976-428f-a9c8-c83b02f89305",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.with(\"Neptune#ml.endpoint\",\"${endpoint_inductive}\").\n",
    "    with(\"Neptune#ml.limit\",10).\n",
    "      V().hasId('user_20000').\n",
    "        out('user_live_cell')\n",
    "        .with(\"Neptune#ml.prediction\")\n",
    "        .with(\"Neptune#ml.inductiveInference\")\n",
    "        .hasLabel('cell')\n",
    "        .id()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "564439aa-f2be-445c-b5f2-702788bf37e3",
   "metadata": {},
   "source": [
    "<div style=\"background-color:#eeeeee; padding:20px; text-align:left; border-radius:10px; margin-top:10px; margin-bottom:10px; \"><b>Information</b>: both cell_34832, cell_19832 are in the ground truth linked to user_20000 </div>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0fec4f30-bc77-466e-8421-0085946b5a9f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}